home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / ISSUE22 / TIMING / DEMO.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1997-03-22  |  2.6 KB  |  137 lines

  1. program Demo;
  2.  
  3. { This program demonstrates the use of the units HIRESTMR and
  4.   PROFIT under DOS. Compile this program with BP7.
  5.  
  6.   IMPORTANT - set the conditional define 'TMPR' before compiling
  7.   and running to enable the profiler.
  8. }
  9.  
  10.  
  11. {$I LibDef.inc}
  12.  
  13.  
  14. uses
  15.  {$IFDEF TargetDelphi1}
  16.  WinCrt,
  17.  {$ENDIF}
  18.  
  19.  HiResTmr,
  20.  Profit;
  21.  
  22.  
  23. {$IFDEF TargetDelphi2}
  24. {$APPTYPE CONSOLE}
  25. {$ENDIF}
  26.  
  27. const
  28. {$IFDEF TargetDelphi1}
  29.   s_Target = '16-bit windows by Delphi1';
  30. {$ENDIF}
  31.  
  32. {$IFDEF TargetDelphi2}
  33.   s_Target = '32-bit windows by Delphi2';
  34. {$ENDIF}
  35.  
  36. {$IFDEF TargetRealMode}
  37.   s_Target = '16-bit DOS Real mode by BP7';
  38. {$ENDIF}
  39.  
  40. {$IFDEF TargetProtectedMode}
  41.   s_Target = '16-bit DOS Protected mode by BP7';
  42. {$ENDIF}
  43.  
  44.  
  45. var
  46.  I : integer;
  47.  L : longint;
  48.  
  49. begin
  50.  Writeln;
  51.  Writeln;
  52.  Writeln( '> Demonstration of HIRESTMR timer unit and PROFIT profiler unit. <' );
  53.  Writeln( '  (C) B.J.Frost 1997' );
  54.  Writeln( '  Compiled for ' + s_Target );
  55.  If b_WindowsInstalled then
  56.    Writeln( '  Windows version is ', w_WindowsVersion )
  57.   else
  58.    Writeln( '  Running under DOS.' );
  59.  
  60.  
  61.  Writeln( '  This shows various methods to achieve a 1s delay with a' );
  62.  Writeln( '  high resolution ..' );
  63.  Writeln;
  64.  Writeln( '  On this PC the minimum accurate delay is ',
  65.            1e6 * (r_CounterCallOverhead.QuadPart / r_CountsPerSec.QuadPart) : 0 : 1,
  66.            'us' );
  67.  
  68.  
  69.  { Open the profiler clock }
  70.  TMPROpen( 'TIMES.TXT', 100 );
  71.  
  72.  
  73.  { First 1s delay using a floating-point value }
  74.  
  75.    Write( '   Single 1s delay .. ' );
  76.  
  77.    { Mark this point in the profile output file as '0' }
  78.    TMPRMark( 0 );
  79.  
  80.    { Do the delay .. }
  81.    DelayS( 1.0 );
  82.  
  83.    { Mark this point in the profile output file as '1' }
  84.    TMPRMark( 1 );
  85.  
  86.    Writeln( 'done.' );
  87.  
  88.  
  89.  
  90.  { Second 1s delay calling a 1ms delay routine 1000 times.. }
  91.  
  92.    Write( '   1s delay from 1000 x 1ms .. ' );
  93.    TMPRMark( 2 );
  94.    For I := 1 to 1000 do
  95.      DelayMS( 1 );
  96.    TMPRMark( 3 );
  97.    Writeln( 'done.' );
  98.  
  99.  
  100.  
  101.  { Third 1s delay calling a 100us delay routine 10,000 times.. }
  102.  
  103.    Write( '   1s delay from 10,000 x 100us .. ' );
  104.    TMPRMark( 4 );
  105.    For I := 1 to 10000 do
  106.      DelayUS( 100 );
  107.    TMPRMark( 5 );
  108.    Writeln( 'done.' );
  109.  
  110.  
  111.  
  112.  { This calls a 10us delay routine 100,000 times.. }
  113.  
  114.    Write( '   1s delay from 100,000 x 10us .. ' );
  115.    TMPRMark( 6 );
  116.    For L := 1 to 100000 do
  117.      DelayUS( 10 );
  118.    TMPRMark( 7 );
  119.    Writeln( 'done.' );
  120.  
  121.  
  122.  
  123.  { Closes the timing profiler }
  124.  TMPRClose;
  125.  
  126.  Writeln( '  See file TIMES.TXT for timings of these delays.' );
  127.  Writeln( '  Press a key ..' );
  128.  Readln;
  129.  
  130. end.
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.